<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加课程</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
    <%@include file="/pages/head/head.jsp" %>
     
  </head>
  
  <body>
   <div id="wrapper">
        <!-- 左边菜单 -->
         <%@include file="/pages/left/leftmenu.jsp" %>

        <div id="page-wrapper" class="gray-bg dashbard-1">
             <!-- 引入top菜单 -->
              <%@include file="/pages/left/topmenu.jsp" %>
            
            <!--左边内容开发，开始  -->
              <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>课程资料</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                            <a>课程资料</a>
                        </li>
                        <li>
                            <strong>添加课程资料</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
                <div class="row">
                    <div class="col-lg-14">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>添加课程资料</h5>
                                <div class="ibox-tools">
                                    <a class="collapse-link">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="ibox-content">
                                <form class="form-horizontal m-t" id="courses" name="courses" method="post" >
                                
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">课程编号：</label>
                                        <div class="col-sm-8">
                                            <input id="code" name="code"  maxlength="30"  class="form-control" type="text">
                                            <input id="coId" name="co_id"  maxlength="30"  class="form-control" type="hidden">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">课程名称：</label>
                                        <div class="col-sm-8">
                                            <input id="courseName" name="courseName" maxlength="30" class="form-control" type="text">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <div class="col-sm-8 col-sm-offset-3">
                                            <button class="btn btn-primary" id="submitbutton" onclick="checkFyFhSubmit()" type="button">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         

        </div>
    </div>
     <%@include file="/pages/head/foot.jsp" %>
    
      <!-- simditor -->

    <script>
    
        
        /** 表单验证  **/
    	function validateForm(){
    		if($("#code").val()==""){
    			alert("课程编号不可以为空");
    			return false;
    		}
    		if($("#courseName").val()==""){
    			alert("课程名称不可以为空");
    			return false;
    		}
    		
    		return true;
    	}
    	
    	 function checkFyFhSubmit(){
    		 if(validateForm()){
    			 
    			 $.ajax({
    					type:"POST",
    					url:"${pageContext.request.contextPath}/course/addCourse.do",
    					data:$("#courses").serialize(),
    					async: true,
    					dataType: "text", 
    		  			error: function(request) {alert("添加信息失败！"+request.responseText);},
    					success:function(data){
    						var result=String($.trim(data));
    						if(result == "succ"){
    							alert("操作成功");
    							window.location.href="./pages/course/addCourse.jsp";
    						}
    						else{
    							alert("操作失败：课程编号不能重复");
    						}
    						
    					}
    				});
    			 
    		 }
    		
    	} 
    </script>
  </body>
</html>
